package com.Springdemo.service.Impl;

import com.Springdemo.dao.OrderMapper;
import com.Springdemo.enity.Order;
import com.Springdemo.enity.OrderExample;
import com.Springdemo.enity.User;
import com.Springdemo.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: lool
 * @Date: 2022-06-09 16:35
 * @Description:
 */
@Service("OrderService")
public class OrderServiceImpl implements OrderService {
    @Autowired
    private OrderMapper orderMapper;

    public OrderMapper getOrderMapper() {
        return orderMapper;
    }

    public void setOrderMapper(OrderMapper orderMapper) {
        this.orderMapper = orderMapper;
    }

    @Override
    public Order findById(int id) {
        OrderExample example=new OrderExample();
        OrderExample.Criteria criteria=example.createCriteria();
        criteria.andIdEqualTo(id);
        Order order=orderMapper.selectByPrimaryKey(id);
        return order;
    }

    @Override
    public List<Order> findAllOrders(int uid) {
        OrderExample orderExample=new OrderExample();
        OrderExample.Criteria criteria=orderExample.createCriteria();
        criteria.andUseridEqualTo(uid);
        List<Order> list=new ArrayList<Order>();
        list=orderMapper.selectByExample(orderExample);
        return list;
    }

    @Override
    public int buyFruit(Order order) {
        orderMapper.insert(order);
        return 200;
    }
}
